define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wx/wxpro/index',
                    add_url: 'wx/wxpro/add',
                    edit_url: 'wx/wxpro/edit',
                    del_url: 'wx/wxpro/del',
                    multi_url: 'wx/wxpro/multi',
                    import_url: 'wx/wxpro/import',
                    copys_url: 'wx/wxpro/copys',
                    adds_url: 'wx/wxpro/adds',
                    pro_url: 'wx/wxpro/config',
                    ministrial_url: 'wx/wxpro/ministrial',
                    table: 'wxpro',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'code', title: __('Code'), editable: true, sortable: true},
                        {field: 'name', title: __('Name'), editable: true, operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'kg', title: __('Kg'), operate:'BETWEEN', editable: true, sortable: true},
                        {field: 'ministrial', title: __('码洋'), operate:'BETWEEN', editable: true, sortable: true},
                        {field: 'weigh', title: __('Weigh'), editable: true},
                        {field: 'type', title: __('Type'), searchList: typeList, editable: {type: 'select', pk: 1, source: typeList}},
                        {field: 'fenlei_text', title: __('产品分类'),operate:false},
                        {field: 'kemu_text', title: __('科目'),operate:false},
                        {field: 'banben_text', title: __('版本'),operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
          $(document).on("click", ".btn-config", function () {
            Fast.api.open('wx/wxpro/config', '分类配置', $(this).data() || {});
          });
        },
        add: function () {
            Controller.api.bindevent();
        },
        config: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});